package com.fxwater.websocket.controller;

import cn.hutool.core.util.StrUtil;
import com.fxwater.websocket.service.impl.SelectDataInfoImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/selectDataInfoController")
public class SelectDataInfoController {



    /**
     * 根据code查询泵站信息
     *
     * @param pumpcode
     * @return
     */
    @RequestMapping(value = "/itemList/{pumpcode}",method = RequestMethod.POST,produces={"application/json"})
    @ResponseBody
    public List<Map<String, Object>> stationList(@PathVariable("pumpcode") String pumpcode){
        SelectDataInfoImpl selectDataInfo = new SelectDataInfoImpl();
        List<Map<String, Object>> resultList = selectDataInfo.selectItemInfoByPumpCode(pumpcode);
        return resultList;
    }

    /**
     * 查询泵站信息
     *
     * @return
     */
    @RequestMapping(value = "/stationList",method = RequestMethod.POST,produces={"application/json"})
    @ResponseBody
    public List<Map<String, Object>> stationList(){
        SelectDataInfoImpl selectDataInfo = new SelectDataInfoImpl();
        List<Map<String, Object>> pumpStationInfoList = selectDataInfo.selectPumpStationInfoList();
        return pumpStationInfoList;
    }

    /**
     *根据检测项及泵站名称及日期区间获取结果
     *
     * @param
     * @return
     */
//    @RequestMapping(value = "/info/{item}/{itemCode}/{time}",method = RequestMethod.POST,produces={"application/json"})
//    @ResponseBody
    public List<Map<String, Object>> info(@PathVariable("item") String item, @PathVariable("itemCode") String itemCode,
                                          @PathVariable("time") String time){
        SelectDataInfoImpl selectDataInfo = new SelectDataInfoImpl();
        List<Map<String, Object>> pumpStationInfoList = selectDataInfo.selectInfo(item, itemCode, time);
        return pumpStationInfoList;
    }


    /**
     *根据检测项及泵站名称及日期区间获取结果
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/info/{itemCode}/{startTime}/{endTime}",method = RequestMethod.GET,produces={"application/json"})
    @ResponseBody
    public Map<String,Object> selectByTime( @PathVariable("itemCode") String itemCode
                                        ,@PathVariable("startTime") String startTime
                                        , @PathVariable("endTime") String endTime){
        Map<String,Object> resultMap = new HashMap<>();
        if(StrUtil.isBlank(itemCode)){
            resultMap.put("success",false);
            resultMap.put("message","检测项编码不能为空");
            return resultMap;
        }
        if(StrUtil.isBlank(startTime)){
            resultMap.put("success",false);
            resultMap.put("message","数据查询开始时间不能为空");
            return resultMap;
        }
        if(StrUtil.isBlank(endTime)){
            resultMap.put("success",false);
            resultMap.put("message","数据查询结束时间不能为空");
            return resultMap;
        }
        SelectDataInfoImpl selectDataInfo = new SelectDataInfoImpl();
        List<Map<String, Object>> pumpStationInfoList = selectDataInfo.selectByTime(null, itemCode, startTime,endTime,null);
        resultMap.put("success",true);
        resultMap.put("message","数据查询成功");
        resultMap.put("data",pumpStationInfoList);
        return resultMap;
    }

}
